import dxRequest from "../../network/index"
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    book_id: {
      type: String | Number,
      value: ""
    },
    bookInfo: {
      type: Object,
      value: {}
    },
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    borrow() {
      // console.log('borrow');
      // console.log("bookInfo", this.data.bookInfo)
      console.log(getApp().globalData.userInfo);

      dxRequest("post", "/borrow/subscribe", {
        user_id: getApp().globalData.userInfo.openid,
        book_id: this.data.bookInfo.book_id,
        status: "1"
      })
        .then(res => {
          // console.log(res);
          if (res.statusCode == 400) {
            wx.showToast({
              title: res.data.msg,
              icon: "error"
            })
            return
          }
          if (res.statusCode == 201) {
            wx.showToast({
              title: '预约成功',
            })
            console.log(res);
          }
          else {
            wx.showToast({
              title: '预约失败',
              icon: "error"
            })
          }
        })
    }
  }
})